package com.ltedu.user.service.impl;

import com.ltedu.user.domain.Teacher;
import com.ltedu.user.domain.vo.TeacherVO;
import com.ltedu.user.mapper.TeacherMapper;
import com.ltedu.user.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 * 讲师表 服务实现类
 * </p>
 *
 * @author Jerry
 * @since 2020-11-26
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean add(TeacherVO teacherVO) {
        Teacher teacher = new Teacher();
        BeanUtils.copyProperties(teacherVO, teacher);
        teacher.setGmtCreate(new Date());
        teacher.setGmtModified(new Date());
        return this.baseMapper.insert(teacher) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean update(TeacherVO teacherVO) {
        Teacher teacher = new Teacher();
        BeanUtils.copyProperties(teacherVO, teacher);
        teacher.setGmtModified(new Date());
        return this.baseMapper.updateById(teacher) > 0;
    }
}
